<template>
  <el-form ref="form" label-width="70px" :model="loginForm" class="login-container" :inline="true">
    <h3 class="login_title">系统登录</h3>
    <el-form-item label="用户名" prop="username">
        <el-input v-model="loginForm.username" placeholder="请输入账号"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
        <el-input v-model="loginForm.password" placeholder="请输入密码" type="password"></el-input>
    </el-form-item>
    <el-form-item>
        <el-button style="margin-left: 105px;" @click="onLogin" type="primary" >登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { getCurrentInstance, reactive } from "vue";
import { useStore } from 'vuex';
import { useRouter } from 'vue-router'

export default {
    setup(){
        const { proxy } = getCurrentInstance()
        const store = useStore()
        const router= useRouter()

        const loginForm = reactive({
            username:'admin',
            password:'admin',
        })

        const onLogin = async ()=>{
            const res =  await proxy.$api.getMenu(loginForm)
            //console.log(res);
            store.commit('SET_MENU',res.menu)
            store.commit('ADD_MENU',router)
            store.commit('SET_TOKEN',res.token)
            router.push({ name:'home' })
        }
        return {
            loginForm,
            onLogin
        }
    }
}
</script>

<style lang="less" scoped>
.login-container{
    width: 350px;
    border: 1px solid #eaeaea;
    margin: 180px auto;
    padding: 35px 35px 15px 35px;
    background-color: #fff;
    border-radius: 15px;
    box-shadow: 0 0 25px #cac6c6;
    box-sizing: border-box;
    .login_title{
        text-align: center;
        margin-bottom: 40px;
    }
    .el-input{
        width: 198px;
    }
}
</style>